$(function() {
    tinymce.init({
        selector: "textarea",
        theme: "modern",
        width: 700,
        height: 300,
        language: 'fr_FR',
        menubar: false,
        toolbar: "undo redo | styleselect | bold italic underline | forecolor backcolor | link | table | charmap code preview",
        plugins: [
            "link image lists charmap preview hr wordcount table code textcolor"
        ]
    });

    $('.datepicker').datepicker({
        dateFormat: 'yy-mm-dd',
        showAnim: 'fade'
    });
    
    $("input.numeric").keypress(function(e) {          
        var key = e.charCode || e.keyCode || 0;                     
        var keychar = String.fromCharCode(key);
        
        //if ( ( ( key == 8 || key == 9 || key == 46 || key == 35 || key == 36 || ( key >= 37 && key <= 40 ) ) && e.charCode==0 )
        if ( ( ( key == 8 || key == 9 || key == 46 || key == 35 || key == 36 || ( key >= 37 && key <= 40 ) ) )
                || ( key >= 48 && key <= 57 ) || key == 0 || key == 13) { /* 0-9 */
            return;
        } else {
            e.preventDefault();
        }
    });
});

function confirmDelete(uri) {
    if(confirm('Voulez vous supprimer?')) {
        window.location = uri;
    }
}

function goTo(uri) {
    window.location = uri;
}

function deleteFile(el, filename, msg) {
    if(confirm(msg)) {
        $.ajax({
            type: 'POST',
            url: 'index.php?controller=annonce&view=deletefile',
            data: { filename: filename },
            success: function() {
                $(el).fadeOut('slow');
            }
        });
    }
}

function changeStatut(id_annonce, statut) {
    $.ajax({
        type: 'POST',
        url: 'index.php?controller=annonce&view=changestatut',
        data: { id_annonce: id_annonce, statut: statut},
        success: function() {
            goTo('index.php?controller=annonce');
        }
    });
}